package com.example.starter.work6

/**
@author whd
@date 2023/10/12 12:08:05
 */
import org.apache.rocketmq.client.producer.DefaultMQProducer
import org.apache.rocketmq.client.producer.SendResult
import org.apache.rocketmq.common.message.Message

fun main() {
  val producer = DefaultMQProducer("YourProducerGroup")
  producer.namesrvAddr = "YourNameServerAddress"
  producer.start()

  try {
    // 创建消息
    val message = Message("topic", "YourTags", "Hello, Scheduled RocketMQ!".toByteArray())

    // 设置消息的延迟时间，单位是毫秒
    val delayTime1 = 53000L // 53 秒
    val delayTime2 = 67000L // 67 秒

    // 发送第一条消息，设置延迟时间为 53 秒
    val sendResult1: SendResult = producer.send(message, delayTime1)
    println("Sent message 1: $sendResult1")

    // 发送第二条消息，设置延迟时间为 67 秒
    val sendResult2: SendResult = producer.send(message, delayTime2)
    println("Sent message 2: $sendResult2")
  } catch (e: Exception) {
    e.printStackTrace()
  } finally {
    producer.shutdown()
  }
}
